1. Field of the Invention
The invention generally relates to an apparatus of recording data using a memory, and in particular, to an electronic apparatus of sequentially recording data using a non-volatile memory.
2. Description of Related Art
Memories can be classified into volatile memories and non-volatile memories according to characteristics thereof. The volatile memories include DRAM and SRAM, which have advantages such as high speed of reading and writing, no need for erasing, and rewritable ability. However, the data stored in the volatile memory is lost easily after the system is powered off (power supply is suspended). On the contrary, the data stored in the non-volatile memory will not be lost after the system is powered off, but it is necessary to erase the old data before writing other new data. There are various non-volatile memories, and the most significant one of which is Flash memory.
The characteristic of the non-volatile memory is that the bit value can only be changed from 1 to 0, and cannot be changed from 0 to 1. When it is required to change 0 to 1, an erasing action is needed. FIG. 1 is a schematic view illustrating the characteristics of the conventional non-volatile memory. Referring to FIG. 1(a), it is assumed that the data originally stored in the non-volatile memory is 1010, when it intends to write data 1000, it is only necessary to change a third bit in the original data 1010 from 1 to 0, without performing the easing. However, as shown in FIG. 1(b), when it intends to write data 1011, the system cannot change 0 to 1, so it is impossible to change a fourth bit of the data 1010 from 0 to 1. At this time, as shown in FIG. 1(c), it is necessary to erase the data 1010 to 1111 first, and then write the data 1011, i.e., change a second bit of the data 1111 from 1 to 0, thereby successfully finishing the action of writing the data.
FIG. 2 is a flow chart of a conventional method for recording data using the non-volatile memory. Referring to FIG. 2, the conventional method for recording data includes preparing input data first (step S202), transforming a main body of the input data into a specific data structure (step S204), and looking up an address correspondingly storing the kind of input data in the non-volatile memory (step S206). Particularly, when performing writing on the non-volatile memory, usually one section is used as a unit, and the sector programs the data structure during storing according to the type of the input data. Therefore, every time when the data is written, it is necessary to transform the data into the data structure corresponding to the sector first and look up the address of the sector, so as to correctly write the input data. For example, FIG. 3 shows the data structure of the conventional system parameters. Referring to FIG. 3, a plurality of sectors storing the parameter data (including sectors 302 to 308) are programmed in the non-volatile memory, and when user needs to write the data into the memory, it is necessary to transform the data into the corresponding data structure before writing the data into the sectors 302 to 308.
After the address storing the input data is decided, it is checked whether the sector of the non-volatile memory in which the data is to be written is empty (step S208). If yes, it represents that all the bit values in the sector are 1, so the erasing step is not required, and the input data can be directly written using a byte as a modifying unit (step S210), that is, when performing the writing action once, the data of at least one byte is updated. On the contrary, if no, it represents that the bit values of some bits in the sector are 0, so the erasing is required (step S212). After erasing, similarly, the input data can be written into the sector of the non-volatile memory using a byte as the modifying unit (step S210).
By the conventional method, it is necessary to erase the non-volatile memory each time when performing writing, which consumes the life of the non-volatile memory. Therefore, in order to reduce the times for erasing the non-volatile memory, a conventional method of successively writing is also provided, that is, when the size of the input data is smaller than a sector, and unused space of the sector is sufficient, new data can be successively written after the previous input data. FIG. 4 is a flow chart of the conventional method for recording data using the non-volatile memory. Referring to FIG. 4, in this method, input data is prepared first (step S402), next a main body of the input data is transformed into a specific data structure (step S404), and an address correspondingly storing the type of input data is looked up in the non-volatile memory (step S406). The above steps are the same as those in the above conventional method for recording data using the non-volatile memory, so the details are not described here.
However, the difference lies in that in step S408, it is checked whether the sector of the non-volatile memory in which the input data has the unused space (step S408). If it is found that the sector of the non-volatile memory has the unused space after checking, the method is changed to directly write the new data after the previous set of data using the byte as the modifying unit (step S410). On the contrary, if the unused space does not exist or the unused space is insufficient, erasing is performed first (step S412), and after erasing, the new data is written into the erased section of the non-volatile memory using the byte as the modifying unit (step S414). It can be understood that although this method can decrease the erasing times, but the minimal unit performing the writing is still one byte, which still results in the waste of space.
To sum up, disadvantages for using the non-volatile memory lie in that erasing times are plenty, and a lot of time is needed by erasing since one sector is used as the unit for each erasing. Generally, sector erase time of a flash is approximately 1 (general count) to 8 (maximal count) seconds, and byte programming time of the flash is approximately 35 (general count) to 300 (maximal count) seconds. In addition, by the above two methods, it is still necessary to frequently perform erasing and rewriting actions. When system configuration or other information is stored in the non-volatile memory, the operation of the system might be unsmooth due to long erasing time. Further, erasing and writing life of a common non-volatile memory is approximately 100,000 times, and frequent erasing and rewriting may shorten the life time and reduce the reliability of the non-volatile memory.